﻿using System;
using System.Xml;

namespace Jayden.Dll.Core.Persistence.Xml
{
	public class XmlDocumentProxy : IDisposable
	{
		private XmlDocumentLock m_DocumentLock;
		private XmlDocument m_Document;
		private bool m_WriteAccess;

		public XmlDocumentProxy(XmlDocumentLock docLock, XmlDocument doc, bool writeAccess)
		{
			m_DocumentLock = docLock;
			m_Document = doc;
			m_WriteAccess = writeAccess;
		}

		public XmlDocument Document { get { return m_Document; } }
		public bool WriteAccess { get { return m_WriteAccess; } }

		public void Dispose()
		{
			if (m_Document != null)
				m_Document = null;
			if (m_DocumentLock != null)
			{
				m_DocumentLock.ReleaseDocument(m_WriteAccess);
				m_DocumentLock = null;
			}
		}
	}
}
